package de.godlike.webgui.internal;

import javax.faces.context.FacesContext;

/**
 * This class provides functionality for bean-handling.
 * 
 * @author asmodaeus
 * 
 */
public class BeanManager {
	/**
	 * Retrieves the given bean from FacesContext and returns it.
	 * 
	 * @param beanName
	 *            name of the bean to retrieve.
	 * @param beanClass
	 *            class of the bean.
	 * @return the casted bean.
	 */
	public static <T> T findBean(String beanName, Class<T> beanClass) {
		FacesContext context = FacesContext.getCurrentInstance();
		return beanClass.cast(context.getApplication().evaluateExpressionGet(
				context, "#{" + beanName + "}", beanClass));
	}
}
